package cn.jdy.plugins.service;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.SQLQuery;
import org.springframework.stereotype.Service;

import cn.jdy.framework.db.hibernate.BaseDao;
import cn.jdy.plugins.entity.Associations;

/**
 * @author wuzhiliang
 * @title : 文章操作实现
 */
@Service
public class AssociationsService extends BaseDao<Associations> {

//	@Autowired
//	private ConfService confService;
	//查id，depars
		public Map<String, Object> getnums(String name) {
			Map<String, Object> map = new HashMap<String, Object>();
		   // String sql = "SELECT COUNT(id) FROM associations WHERE "+name+" IS NOT NULL";
			String sql = "SELECT COUNT(id) FROM news WHERE isarticle='1' and username='"+name+"' ";
		    SQLQuery query = super.em().createSQLQuery(sql.toString());
		    map.put("dataList", query.list());
		    return map;
		  }
		
		/**
		   * 查询部门
		   * @return
		   */
		  public long autils(String name){
			  Map<String, Object> map=this.getnums(name);
			  List list=(List)map.get("dataList");//cnt
			  int imax=list.size();
			  for(int i=0;i<imax;i++){
				  Long cnt = ((BigInteger) list.get(i)).longValue();
				  return cnt;
			  }
			  return 0;
		  }
		  
		  public List getnumgroup(String name) {
			   // String sql = "SELECT COUNT(id) FROM associations WHERE "+name+" IS NOT NULL";
				String sql = "SELECT COUNT(id) as status,columnId FROM news t WHERE t.isarticle='1' and t.username='"+name+"' GROUP BY t.columnId";
			    SQLQuery query = super.em().createSQLQuery(sql);
			 
			    return  query.list();
			  }
		  
		  public long autilgroup(String name){
			  
			List list=this.getnumgroup(name);
			Long cnt=(long) 0;
			for (int i = 0; i < list.size(); i++) {
				
				Object[] ob=(Object[]) list.get(i);
			//	System.out.println(ob[0]+"");
			//	System.out.println(ob[1]+"");
				cnt=cnt+Integer.parseInt(String.valueOf(ob[0]))*aautils(String.valueOf(ob[1]));
			}
			  return cnt;
		  }
		  
		  public int aautils(String name){
			  int namenum=0;
			  switch(name){
			  case "9736":namenum = 1;break;
			  case "9737":namenum = 1;break;
			  case "9759":namenum = 5;break;
			  case "9778":namenum = 0;break;
			  case "9760":namenum = 5;break;
			  case "9916":namenum = 20;break;
			  case "9917":namenum = 20;break;
			  case "9920":namenum = 2;break;
			  case "9921":namenum = 5;break;
			  case "9923":namenum = 1;break;
			  case "9924":namenum = 1;break;
			  case "9926":namenum = 5;break;
			  case "10238":namenum = 5;break;
			  case "10239":namenum = 5;break;
			  case "10240":namenum = 5;break;
			  case "9925":namenum = 0;break;
			  case "9670":namenum = 5;break;
			  case "9802":namenum = 5;break;
			  case "9672":namenum = 5;break;
			  case "9665":namenum = 10;break;
			  case "9738":namenum = 1;break;
			  }
			  return namenum;
		  }

}
